//
//  DetailOfCircleTableViewCell.m
//  LoveOfPet
//
//  Created by 芦彬 on 15/11/17.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "DetailOfCircleTableViewCell.h"
#import "LuBDefine.h"

#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"

@implementation DetailOfCircleTableViewCell

- (void)dealloc{
    [_detailOfCircle release];
    [_photoImageView release];
    [_avatarImageView release];
    [_disnameLabel release];
    [_photo_desLabel release];
    [_sexLabel release];
    [_zanLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createDetailOfCircleViewCell];
    }
    return self;
}

- (void)createDetailOfCircleViewCell{
    self.selectionStyle = 0;
    
    self.photoImageView = [[UIImageView alloc]init];
//    self.photoImageView.backgroundColor = [UIColor redColor];
    [self addSubview:_photoImageView];
    [_photoImageView release];
    
    self.avatarImageView = [[UIImageView alloc]init];
//    self.avatarImageView.backgroundColor = [UIColor purpleColor];
    [self.photoImageView addSubview:_avatarImageView];
    [_avatarImageView release];
    
    self.sexLabel = [[UILabel alloc]init];
//    self.sexLabel.backgroundColor = [UIColor yellowColor];
    [self addSubview:_sexLabel];
    [_sexLabel release];
    
    self.disnameLabel = [[UILabel alloc]init];
//    self.disnameLabel.backgroundColor = [UIColor blueColor];
    [self addSubview:_disnameLabel];
    [_disnameLabel release];
    
    self.zanLabel = [[UILabel alloc]init];
//    self.zanLabel.backgroundColor = [UIColor brownColor];
    [self addSubview:_zanLabel];
    [_zanLabel release];
    
    self.photo_desLabel = [[UILabel alloc]init];
//    self.photo_desLabel.backgroundColor = [UIColor grayColor];
    [self addSubview:_photo_desLabel];
    [_photo_desLabel release];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.photoImageView.frame = CGRectMake(0, 0, CWIDTH, CHEIGHT / 5 * 3.2);
    
    self.avatarImageView.frame = CGRectMake(20, self.photoImageView.frame.size.height - CWIDTH / 18, CWIDTH / 6, CWIDTH / 6);
    self.avatarImageView.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.avatarImageView.layer.borderWidth = 3;
    
    self.sexLabel.frame = CGRectMake(20 * 2 + self.avatarImageView.frame.size.height, self.photoImageView.frame.size.height + 10, 40, 30);
    self.sexLabel.textColor = [UIColor grayColor];
    self.sexLabel.font = [UIFont systemFontOfSize:13];
    
    self.disnameLabel.frame = CGRectMake(20 * 4 + self.avatarImageView.frame.size.height + self.sexLabel.frame.size.height, self.photoImageView.frame.size.height + 10, WIDTH/ 4, 30);
    self.disnameLabel.textColor = [UIColor colorWithRed:0.9015 green:0.0 blue:0.0 alpha:1.0];
    self.disnameLabel.font = [UIFont systemFontOfSize:14];
    
    self.zanLabel.frame = CGRectMake(WIDTH - WIDTH / 4, self.photoImageView.frame.size.height + 10, WIDTH / 4 - 20, 30);
    self.zanLabel.font = [UIFont systemFontOfSize: 13];
    self.zanLabel.textColor = [UIColor redColor];
    self.zanLabel.textAlignment = NSTextAlignmentRight;
    
    self.photo_desLabel.frame = CGRectMake(20, self.photoImageView.frame.size.height + self.avatarImageView.frame.size.height - 10, WIDTH - 40, 50);
    self.photo_desLabel.numberOfLines = 0;
    self.photo_desLabel.textColor = [UIColor colorWithRed:0.4449 green:0.4449 blue:0.4449 alpha:1.0];
    self.photo_desLabel.font = [UIFont systemFontOfSize:13];
}

- (void)setDetailOfCircle:(DetailOfCircle *)detailOfCircle{
    if (_detailOfCircle != detailOfCircle) {
        [_detailOfCircle release];
        _detailOfCircle = [detailOfCircle retain];
    }
    
    NSURL *photoUrl = [NSURL URLWithString:detailOfCircle.photo];
    [self.photoImageView sd_setImageWithURL:photoUrl placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    
    NSURL *avatarUrl = [NSURL URLWithString:detailOfCircle.avatar];
    [self.avatarImageView sd_setImageWithURL:avatarUrl placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    
    if ([detailOfCircle.sex isEqualToString:@"1"]) {
        self.sexLabel.text = @"🎩公";
    }else{
        self.sexLabel.text = @"🎀母";
    }
    self.disnameLabel.text = detailOfCircle.disname;
    self.zanLabel.text = [NSString stringWithFormat:@"👍%@",detailOfCircle.zan];
    if ([detailOfCircle.photo_des isEqualToString:@""]) {
        
    }
    else{
        self.photo_desLabel.text = detailOfCircle.photo_des;
    }
}

+ (DetailOfCircleTableViewCell *)detailOfCircleTableViewCellWithTableView:(UITableView *)tableView{
    static NSString *detailOfCircleCell = @"detailOfCircleCell";
    DetailOfCircleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:detailOfCircleCell];
    if (!cell) {
        cell = [[[DetailOfCircleTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:detailOfCircleCell] autorelease];
    }
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
